package com.xiaoxing.gongqiju.mvp.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.utils.ArmsUtils;
import com.xiaoxing.gongqiju.R;
import com.xiaoxing.gongqiju.mvp.ui.entity.LiaoCheng_GongQiJu_ShenQingChuKu;
import com.xw.repo.XEditText;

import java.util.List;

//import me.jessyan.armscomponent.commonres.utils.GlideUtil;


public class LiaoCheng_GongQiJu_ShenQingChuKuAdapter extends BaseQuickAdapter<LiaoCheng_GongQiJu_ShenQingChuKu.DataBean, BaseViewHolder> {

    private Context mContext;
    private ILiaoCheng_GongQiJu_ShenQingChuKuAdapter iLiaoCheng_gongQiJu_shenQingChuKuAdapter;

    public LiaoCheng_GongQiJu_ShenQingChuKuAdapter(Context context, @Nullable List<LiaoCheng_GongQiJu_ShenQingChuKu.DataBean> data, ILiaoCheng_GongQiJu_ShenQingChuKuAdapter iLiaoCheng_gongQiJu_shenQingChuKuAdapter) {
        super(R.layout.item_liao_cheng__gong_qi_ju__shen_qing_chu_ku, data);
        this.mContext = context;
        this.iLiaoCheng_gongQiJu_shenQingChuKuAdapter = iLiaoCheng_gongQiJu_shenQingChuKuAdapter;
    }

    @Override
    protected void convert(BaseViewHolder helper, LiaoCheng_GongQiJu_ShenQingChuKu.DataBean item) {
        //GlideUtil.loadImage(mContext,item.getImg(),helper.getView(R.id.img_head));
        helper.setText(R.id.tv_wu_liao_ming_cheng, "物料名称：" + item.getMaterialtoolname());
        helper.setText(R.id.tv_wu_liao_zu_ming_cheng, "物料组名称：" + item.getMaterialGroupName());
        helper.setText(R.id.tv_wu_liao_dan_wei, "物料单位：" + item.getUnit());
        helper.setText(R.id.tv_wu_liao_da_lei_ming_cheng, "物料大类名称：" + item.getMaterialClassName());
        helper.setText(R.id.tv_chuang_jian_shi_jian, "创建时间：" + item.getCreatetime());
        helper.setText(R.id.tv_ku_cun_shu_liang, "库存数量：" + item.getNum());
        helper.setText(R.id.xet_chu_ku_shu_liang, item.getSelectNum());
        EditText xet_chu_ku_shu_liang = helper.getView(R.id.xet_chu_ku_shu_liang);

        xet_chu_ku_shu_liang.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                try {
                    if (s.toString().length() > 0) {
                        if (Double.parseDouble(s.toString()) > Double.parseDouble(item.getNum())) {
                            ArmsUtils.makeText(mContext, "输入的数量不能大于库存数量");
                            xet_chu_ku_shu_liang.setText(item.getNum());
                            item.setSelectNum(item.getNum());
                            iLiaoCheng_gongQiJu_shenQingChuKuAdapter.addData(item);
                        } else {
                            item.setSelectNum(s.toString());
                            iLiaoCheng_gongQiJu_shenQingChuKuAdapter.addData(item);
                        }
                    } else {
                        item.setSelectNum("");
                        iLiaoCheng_gongQiJu_shenQingChuKuAdapter.delData(item);

                    }
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    public interface ILiaoCheng_GongQiJu_ShenQingChuKuAdapter {

        void addData(LiaoCheng_GongQiJu_ShenQingChuKu.DataBean item);

        void delData(LiaoCheng_GongQiJu_ShenQingChuKu.DataBean item);
    }

}
